﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using Cofe.Core;
using Cofe.Core.Utils;

namespace Cofe.Web
{
    [CollectionDataContract(Name = "Links", Namespace = CofeConstants.Namespace, ItemName = "Link")]
    public class XmlLinkList : List<XmlLink>
    {
        public XmlLinkList()
        {

        }

        public XmlLinkList(IEnumerable<XmlLink> links)
            : base(links)
        {

        }
    }

    [DataContract(Name="Link", Namespace = CofeConstants.Namespace)]    
    public class XmlLink 
    {

        #region Constructor

        public XmlLink()
        {

        }

        public XmlLink(MediaType mt, string rt, Uri uri, object property = null)
            : this()
        {
            MediaType = mt; RelationTypeStr = rt; Uri = uri; Property = property;
        }

        public XmlLink(MediaType mt, RelationType rt, Uri uri, object property = null)
            : this(mt,  EnumUtils.GetPropertyName(rt), uri, property)
        {            
        }

        public XmlLink(string mime, RelationType rt, Uri uri, object property = null)
            : this(MediaTypeExtension.ToMediaType(mime), rt, uri, property)
        {

        }

        public XmlLink(string mime, string rt, Uri uri, object property = null)
            : this(MediaTypeExtension.ToMediaType(mime), rt, uri, property)
        {

        }

        
        #endregion

        #region Methods
        


        #endregion

        #region Data
        
        #endregion

        #region Public Properties

        
        public object Property { get; set; }

        [Key]
        public string PropertyStr {
            get { return CofeServices.PropertyDictionary.GetPropertyString(Property); }
            set { Property = CofeServices.PropertyDictionary.GetProperty(value); }
        }

        public MediaType MediaType { get; set; }
        
        [DataMember(Name = "MediaType")]
        public string MediaTypeStr
        {
            get { return MediaTypeExtension.ToMIMEStr(MediaType); }
            set { MediaType = MediaTypeExtension.ToMediaType(value); }
        }

        public RelationType RelationType
        {
            get { return RelationTypeExtension.Parse(RelationTypeStr); }
        }

        [DataMember(Name = "Rel")]        
        public string RelationTypeStr
        {
            get;
            set; 
        }

        [DataMember]
        public Uri Uri { get; set; }

        #endregion

       
        
        
    }
}
